const path = require('path')
const daoModule = require('./Dao')
// 获取数据库模型
const database = require('../modules/databse')

module.exports.clearGoodAttributes = function (goods_id, cb) {
    let db = database.getDataBase()
    let sql = 'DELETE FROM sp_goods_attr WHERE goods_id = ?'
    db.driver.execQuery(sql, [goods_id], function (err) {
        if (err) return cb('删除出错')
        cb(null)
    })
}

module.exports.list = function(goods_id, cb) {
    let db = database.getDataBase()
    let sql = "SELECT good_attr.goods_id,good_attr.attr_id,good_attr.attr_value,good_attr.add_price,attr.attr_name,attr.attr_sel,attr.attr_write,attr.attr_vals FROM sp_goods_attr as good_attr LEFT JOIN sp_attribute as attr ON attr.attr_id = good_attr.attr_id WHERE good_attr.goods_id = ?"
    db.driver.execQuery(sql,[goods_id], function(err, attrs) {
        if (err) return cb('删除出错')
        cb(null, attrs)
    })
}